﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    ///  附件表 逻辑类
    /// </summary>
    public class DocAttach
    {
        /// <summary>
        /// 附件表数据类
        /// </summary>
        private DAL.DocAttach docAttachDAL = new DAL.DocAttach();
        public DocAttach()
        {
        }
        /// <summary>
        /// 获取相关信息的附件列表
        /// <creator>wangl</creator>
        /// <date>2013-08-14</date>
        /// </summary>
        /// <param name="docID">信息编号</param>
        /// <param name="attachType">附件类型</param>
        /// <returns></returns>
        public List<Model.DocAttach> GetDocAttachListByDocID(decimal docID, string attachType)
        {
            DataSet ds = docAttachDAL.GetDocAttachListByDocID(docID, attachType);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获取附件服务器地址
        /// <creator>wangl</creator>
        /// <date>2013-08-14</date>
        /// </summary>
        /// <param name="attachID">附件编号</param>
        /// <returns></returns>
        public string GetAttachSvrAddress(decimal attachID)
        {
            return docAttachDAL.GetAttachSvrAddress(attachID);
        }
         /// <summary>
        /// 删除附件记录
        /// <creator>wangl</creator>
        /// <date>2013-08-14</date>
        /// </summary>
        /// <param name="attachID">附件编号</param>
        public void DeleteDocAttach(decimal attachID)
        {
             docAttachDAL.DeleteDocAttach(attachID);
        }
        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-08-14</date> 
        /// </summary>
        /// <param name="dt">DataTable对象</param>
        /// <returns>信息类别列表</returns>
        private List<ElingOA6_Admin_DSJCJ.Model.DocAttach> DataTableToList(DataTable dt)
        {
            List<ElingOA6_Admin_DSJCJ.Model.DocAttach> modelList = new List<ElingOA6_Admin_DSJCJ.Model.DocAttach>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ElingOA6_Admin_DSJCJ.Model.DocAttach model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = docAttachDAL.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
        public List<string> GetSvrFileNameAndOldName(decimal attachID)
        {
            List<string> list = new List<string>();

            DataSet ds = docAttachDAL.GetSvrFileNameAndOldName(attachID);
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds.Tables[0].Rows[0];
                list.Add(row["FAttachSvrFileName"].ToString());
                list.Add(row["FAttachOldFileName"].ToString());
            }

            return list;
        }
    }
}
